<template>
    <div>
        <h2>登录</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">用户名</td>
                    <input type="text" v-model="queryInfo.username" />
                </tr>
                <tr>
                    <td align="right">密码</td>
                    <input type="password"  v-model="queryInfo.password"/>
                </tr>
                <tr>
                    <td align="right"></td>
                    <input type="button" value="登录" @click="ok" />
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter , useRoute } from 'vue-router'
import axios from 'axios';
let router = useRouter();   
let route = useRoute();
let queryInfo=reactive({
    username:'',
    password:''
})
const ok=()=>{
    if(queryInfo.username==''||queryInfo.password==''){
        alert('请输入用户名和密码')
        return;
    }
    axios({
        url:'/api/User/Login',
        method:'get',
        params:queryInfo
    })
    .then((res)=>{
        if(res.data==1){
          alert('登录成功')
          router.push({path:'/RoomNumberList'})
        }
        else if(res.data==-1){
            alert('用户名不存在')
        }
        else if(res.data==-2){
            alert('密码错误')
        }
        else{
            alert('登录失败')   
        }
    })

}
</script>

<style scoped>

</style>